//
// Author    : Pablo Bosch 
// Contact   : pboschvivancos@epo.org
// Created Modif: 13/03/2005
// Last Modif: 13/04/2005

var MOD_SPN={
  xmlresp:new ActiveXObject("Microsoft.XMLDOM"),
  title:"",
  pd:"",
  pri:"",
  callback:""
};

if(!MOD_SPN.xmlresp) {
  alert("Cannot initialize XMLRESP");
}

MOD_SPN.espacenetdocs=["A","A1","A2","A3","B","B1","B2"];

MOD_SPN.onchangepn_ajax = function(cl,resp){
  var msg="";
  var bib=0;
  var xmlres={};
  if(resp.xml) {
    MOD_SPN.xmlresp.loadXML(resp.xml);
    var xml=MOD_SPN.xmlresp.selectSingleNode("//return");
    // B111EP @DATE pub date
    // B311EP @DATE pri date (list of), takes first
    // B570EP TXT abs
    // B542   TXT TI 
    if(xml) {
      //html_popup("debug",resp.xml,"resize");
      MOD_SPN.xmlresp.loadXML(xml.childNodes[0].nodeValue);
      if(MOD_SPN.xmlresp.selectSingleNode("//ERRORS")) {
	if(GetPrefsDebugging()) {
	  alert(xml.childNodes[0].nodeValue);
	}
	return;
      } 
      var espdoc_iter= new array_iterator(MOD_SPN.espacenetdocs);
      while(!espdoc_iter.end() && !bib) {
	bib=MOD_SPN.xmlresp.selectSingleNode("//BIBLIO/SDOBI/B131EP[ text()='"+espdoc_iter.getValue()+"']");
	espdoc_iter.next();
      }      
      if(bib && bib.parentNode) {
	MOD_SPN.title=(bib.parentNode.selectSingleNode("B542") 
		       && bib.parentNode.selectSingleNode("B542").text) || "No title";
	MOD_SPN.pd   =(bib.parentNode.selectSingleNode("B111EP") 
		       && normalizeDate(bib.parentNode.selectSingleNode("B111EP").getAttribute("DATE")))|| "";
	MOD_SPN.pri  =(bib.parentNode.selectSingleNode("B311EP[@DATE!='']")
		       &&normalizeDate(bib.parentNode.selectSingleNode("B311EP[@DATE!='']").getAttribute("DATE")))||"";
	if(MOD_SPN.callback) {
	  MOD_SPN.callback(MOD_SPN.title,MOD_SPN.pd,MOD_SPN.pri);
	}
      } else {
	alert("Empty bib entry ?");
      }	
    } else {
      alert("Empty reply");
    }
  }
}



function checkespacenet(pn,callback) {
  var pl = new SOAPClientParameters();
  MOD_SPN.callback=callback;
  pl.add("input_request","xsi_type=\"xsd:string\"",
	 "<OpenPatentServices ACTION=\"Biblio\"> <WORLDPATENTDATA><BIBLIO SEED=\""+pn+"\" "+
	 " SEED_FORMAT=\"E\" SEED_TYPE=\"PN\" /></WORLDPATENTDATA></OpenPatentServices>");
  SOAPClient.invoke("http://ops.espacenet.com/OpenPatentServices/webService",
		    "getPatentData", pl, true,MOD_SPN.onchangepn_ajax);      
}









  
